package com.csun.cmny.provider.controller.message.revise;

import com.csun.cmny.base.dto.LoginAuthDto;
import com.csun.cmny.provider.controller.message.AbstractCurTaskQueryProcessor;
import com.csun.cmny.provider.dto.OrderQueryDto;
import com.csun.cmny.provider.model.domain.OmcNursingUserBind;
import com.csun.cmny.provider.model.dto.revise.ReviseQueryDto;
import com.csun.cmny.provider.model.vo.revise.ReviseVo;
import com.csun.cmny.provider.service.OmcNursingUserBindService;
import com.csun.cmny.provider.service.OmcReviseService;
import com.csun.cmny.util.PublicUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-10-11 19:55
 * @Description:
 */
@Slf4j
@Component
public class ReviseCurTaskQuery extends AbstractCurTaskQueryProcessor<ReviseVo> {

    @Resource
    private OmcReviseService omcReviseService;
    @Resource
    private OmcNursingUserBindService omcNursingUserBindService;

    @Override
    protected List<ReviseVo> queryCurTaskList(LoginAuthDto loginAuthDto) {

        ReviseQueryDto reviseQueryDto = new ReviseQueryDto();

        List<Integer> states = omcReviseService.queryCurTaskStates(loginAuthDto);
        if (PublicUtil.isEmpty(states)) {
            // return Lists.newArrayList();
            return null;
        }

        // 根据用户Id获取班组
        OmcNursingUserBind nursingUserBind = new OmcNursingUserBind();
        nursingUserBind.setUserId(loginAuthDto.getUserId());
        nursingUserBind = omcNursingUserBindService.selectOne(nursingUserBind);
        if (nursingUserBind != null && nursingUserBind.getNursingGroupId() != null) {
            reviseQueryDto.setNursingGroupId(nursingUserBind.getNursingGroupId());
        }

        reviseQueryDto.setPageSize(65535);
        reviseQueryDto.setStates(states);
        reviseQueryDto.setGroupId(loginAuthDto.getGroupId());

        return omcReviseService.queryListWithPage(reviseQueryDto);
    }

    @Override
    protected List<ReviseVo> queryCurOrderList(OrderQueryDto orderQueryDto, LoginAuthDto loginAuthDto) {

        ReviseQueryDto reviseQueryDto = new ReviseQueryDto();

//        List<Integer> states = omcReviseService.queryCurTaskStates(loginAuthDto);
//        if (PublicUtil.isEmpty(states)) {
//            // return Lists.newArrayList();
//            return null;
//        }

        // 根据用户Id获取班组
//        OmcNursingUserBind nursingUserBind = new OmcNursingUserBind();
//        nursingUserBind.setUserId(loginAuthDto.getUserId());
//        nursingUserBind = omcNursingUserBindService.selectOne(nursingUserBind);
//        if (nursingUserBind != null && nursingUserBind.getNursingGroupId() != null) {
//            reviseQueryDto.setNursingGroupId(nursingUserBind.getNursingGroupId());
//        }

        reviseQueryDto.setPageSize(65535);
        reviseQueryDto.setStartQueryTime(orderQueryDto.getStartQueryTime());
        reviseQueryDto.setEndQueryTime(orderQueryDto.getEndQueryTime());
//        reviseQueryDto.setStates(states);
        reviseQueryDto.setGroupId(loginAuthDto.getGroupId());

        return omcReviseService.queryListWithPage(reviseQueryDto);
    }


//    @Override
//    protected List<ReviseVo> queryCurTaskList(ReviseCurTaskQueryDto reviseCurTaskQueryDto) {
//
//        ReviseQueryDto reviseQueryDto = new ReviseQueryDto();
//
//        return omcReviseService.queryListWithPage(reviseQueryDto);
//    }

//    @Override
//    public CurTaskVo queryToDoList(LoginAuthDto loginAuthDto) {

//        // 1、获取指定查询器的配置
//
//        // 2、如果配置器有配置，并且该机构生效
//
//        // 3、根据查询器生成查询条件
//
//        // 4、根据查询条件查询待办事项
//
//        ReviseQueryDto reviseQueryDto = new ReviseQueryDto();
//
//        List<ReviseVo> reviseVoList = omcReviseService.queryListWithPage(reviseQueryDto);
//
//        CurTaskVo<ReviseVo> curTaskVo = new CurTaskVo();
//        curTaskVo.setKey("reviseCurTaskQuery");
//        curTaskVo.setName("调房调级待审批列表");
//        curTaskVo.setUrl("revise/list");
//        curTaskVo.setData(reviseVoList);

//        return null;
//    }
}
